package com.itheima.reggie.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Category;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class CategoryController {
    @Autowired
    private CategoryService categoryService;

    //分类列表
    @GetMapping("/category/findAll")
    public ResultInfo findAll() {
        //1.调用servicechaxun
        List<Category> list = categoryService.findAll();
        //2.返回resultInfo结果
        return ResultInfo.success(list);
    }

    //新增分类
    @PostMapping("/category")
    public ResultInfo save(@RequestBody Category category) {
        //1.接收参数
        //2.调用service新增
        categoryService.save(category);
        //3.返回resultInfo结果
        return ResultInfo.success(null);

    }

    @PutMapping("/category")
    public ResultInfo update(@RequestBody Category category) {
        //1接收参数
        //2.调用service修饰
        categoryService.update(category);
        //3.返回resultInfo结果
        return ResultInfo.success(null);
    }

//删除分类
    @DeleteMapping("/category")
    public ResultInfo delete(Long id) {
        //1.接收参数
        //2.调用service删除
        ResultInfo resultInfo = categoryService.delete(id);
        //3.返回删除结果
        return resultInfo;
    }

    //根据type查询分类列表
    // 根据type查询分类列表
    @GetMapping("/category/list")
    public ResultInfo categoryList(Integer type) { // 1.接收请求参数
        // 2.调用service查询
        List<Category> list = categoryService.findByType(type);
        // 3.返回结果
        return ResultInfo.success(list);

    }


}





































































